package socketmvc.server.context;

import org.tio.core.ChannelContext;
import org.tio.core.TioConfig;
import socketmvc.core.config.SocketMvcConfig;
import socketmvc.core.packets.ResponseFuture;
import socketmvc.core.packets.basic.IPacket;

public class SocketChannelThreadWrapper extends SocketChannel {

    public SocketChannel getContext(){
        return ThreadSocketChannelHandler.get();
    }

    @Override
    public IPacket getPacket() {
        return getContext().getPacket();
    }

    @Override
    public void setPacket(IPacket packet) {
        getContext().setPacket(packet);
    }

    @Override
    public Object getAttr(String key) {
        return getContext().getAttr(key);
    }

    @Override
    public Object setAttr(String key, Object val) {
        return getContext().setAttr(key, val);
    }

    @Override
    public Object removeAttr(String key) {
        return getContext().removeAttr(key);
    }

    @Override
    public String getType() {
        return getContext().getType();
    }

    @Override
    public TioConfig getIoConfig() {
        return getContext().getIoConfig();
    }

    @Override
    public void send(IPacket packet) {
        getContext().send(packet);
    }

    @Override
    public boolean sendToUser(String user, IPacket packet) {
        return getContext().sendToUser(user, packet);
    }

    @Override
    public void sendToGroup(String group, IPacket packet) {
        getContext().sendToGroup(group, packet);
    }

    @Override
    public void bindUser(String user) {
        getContext().bindUser(user);
    }

    @Override
    public void bindGroup(String group) {
        getContext().bindGroup(group);
    }

    @Override
    public void unbindUser(String user) {
        getContext().unbindUser(user);
    }

    @Override
    public void unbindGroup(String group) {
        getContext().unbindGroup(group);
    }

    @Override
    public boolean getUserIsOnline(String user) {
        return getContext().getUserIsOnline(user);
    }

    @Override
    public void close() {
        getContext().close();
    }

    @Override
    public IServerContext getServerContext() {
        return getContext().getServerContext();
    }

    @Override
    public void setServerContext(IServerContext serverContext) {
        getContext().setServerContext(serverContext);
    }

    /**
     * 将客户端设置进黑名单
     */
    @Override
    public void setContextToBlacklist() {
        getContext().setContextToBlacklist();
    }

    /**
     * 从黑名单中删除客户端
     */
    @Override
    public void delContextFromBlacklist() {
        getContext().delContextFromBlacklist();
    }

    /**
     * 查看客户端是否在黑名单中
     *
     * @return true在黑名单中，false不在
     */
    @Override
    public boolean isContextInBlacklist() {
        return getContext().isContextInBlacklist();
    }

    @Override
    public String getClientIp() {
        return getContext().getClientIp();
    }

    @Override
    public int getClientPort() {
        return getContext().getClientPort();
    }

    @Override
    public ChannelContext getTarget() {
        return getContext().getTarget();
    }

    /**
     * 将数据包发送到绑定user的context,并等待响应结果
     *
     * @param user   user
     * @param packet 数据包
     * @return 等待结果
     */
    @Override
    public ResponseFuture sendToUserSync(String user, IPacket packet) {
        return getContext().sendToUserSync(user,packet);
    }

    /**
     * 发送数据包到当前context,并等待响应结果
     *
     * @param packet 数据包
     * @return 等待结果
     */
    @Override
    public ResponseFuture sendSync(IPacket packet) {
        return getContext().sendSync(packet);
    }

    /**
     * 获取客户端host信息
     *
     * @return 客户端host信息
     */
    @Override
    public SocketMvcConfig.IpConfig getClientConnInfo() {
        return getContext().getClientConnInfo();
    }

    /**
     * 获取服务端host信息
     *
     * @return 服务端host信息
     */
    @Override
    public SocketMvcConfig.IpConfig getServerConnInfo() {
        return getContext().getServerConnInfo();
    }
}
